﻿// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System.Collections.Generic;
using System.Windows.Media;

using Nova.CodeDOM;

namespace Nova.UI
{
    /// <summary>
    /// The view model for a <see cref="CodeDOM.Namespace"/>.
    /// </summary>
    public class NamespaceVM : CodeObjectVM
    {
        #region /* STATICS */

        internal static void AddViewModelMapping()
        {
            CreateViewModel.Add(typeof(Namespace),
                delegate(CodeObject codeObject, bool isDescription, Dictionary<CodeObject, CodeObjectVM> dictionary) { return new NamespaceVM((Namespace)codeObject, dictionary); });
        }

        #endregion

        #region /* CONSTRUCTORS */

        /// <summary>
        /// Create a view model instance for the specified <see cref="CodeDOM.Namespace"/>.
        /// </summary>
        public NamespaceVM(Namespace @namespace, Dictionary<CodeObject, CodeObjectVM> dictionary)
            : base(@namespace, dictionary)
        { }

        #endregion

        #region /* PROPERTIES */

        /// <summary>
        /// The underlying <see cref="CodeDOM.Namespace"/> model.
        /// </summary>
        public Namespace Namespace
        {
            get { return (Namespace)CodeObject; }
        }

        /// <summary>
        /// Determines if this <see cref="Namespace"/> is root-level (global or extern alias).
        /// </summary>
        public virtual bool IsRootLevel
        {
            get { return false; }
        }

        #endregion

        #region /* METHODS */

        #endregion

        #region /* RENDERING */

        public override Brush BorderBrush
        {
            get { return NamespaceDeclVM.StaticBorderBrush; }
        }

        public override Brush BackgroundBrush
        {
            get { return NamespaceDeclVM.StaticBackgroundBrush; }
        }

        public override void Render(CodeRenderer renderer, RenderFlags flags)
        {
            if (flags.HasFlag(RenderFlags.Description))
            {
                if (flags.HasFlag(RenderFlags.ForceBorder))
                    CreateBorder(renderer, flags);
                renderer.RenderText(NamespaceDecl.ParseToken, KEYWORD_BRUSH, this);
                renderer.RenderText(" ", PUNC_BRUSH, this);
            }

            renderer.RenderText(Namespace.FullName, IDENTIFIER_BRUSH, this);

            // If we have a border, return to the previous one
            if (flags.HasFlag(RenderFlags.ForceBorder))
                renderer.ReturnToBorderParent(this);
        }

        #endregion
    }
}
